import { launch } from 'puppeteer';

export const captureVideo = async (url: string) => {
  const browser = await launch({
    devtools: false,
    headless: false,
    defaultViewport: { width: 1200, height: 1000 },
    // 默认使用 chromium
    // executablePath: '/usr/bin/google-chrome',
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '--allow-http-screen-capture',
      '--enable-usermedia-screen-capturing',
      '--desktop-window-1080p',
      '--auto-select-desktop-capture-source=z-track'
      // '--auto-open-devtools-for-tabs',
      //   '--use-fake-device-for-media-stream',
      //   '--use-fake-ui-for-media-stream',
      // 全屏启动
      // '--start-fullscreen'
      // '--window-size=1024,656',
      // '--no-startup-window'
    ]
  });
  const page = await browser.newPage();
  await page.goto(url);

  await page.exposeFunction('closeBrowser', () => {
    browser.close();
  });
};
